package com.chinackts.auth.model;

import com.alibaba.fastjson.JSON;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.List;

/**
 * @author Lianhong
 * @since 2021/2/24
 * 代理IP
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class ProxyIP implements Serializable {

    private ProxyType proxyType;
    private Object originalMsg;
    private List<Item> items;

    public static ProxyIP applyFor(String proxyResp, ProxyType proxyType) {
        if (ProxyType.QG.equals(proxyType)) {
            ProxyIP_QG proxy = JSON.parseObject(proxyResp, ProxyIP_QG.class);
            return proxy.convert();
        } else if (ProxyType.SYT.equals(proxyType)) {
            ProxyIP_SYT proxy = JSON.parseObject(proxyResp, ProxyIP_SYT.class);
            return proxy.convert();
        } else if (ProxyType.JL.equals(proxyType)) {
            ProxyIP_JL proxy = JSON.parseObject(proxyResp, ProxyIP_JL.class);
            return proxy.convert();
        }
        return null;
    }

    @Data
    @AllArgsConstructor
    @NoArgsConstructor
    public static class Item implements Serializable {
        private String ip;
        private int port;
        private String expireTime;
    }
}
